﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QTime>
#include <QtCharts>
#include <QtCharts/QLineSeries>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QValueAxis>
#include <QtCharts/QSplineSeries>
#include <QPair>
#include <QDateTime>
#include <QFile>
#include <QMutex>
#include <QIODevice>

QT_CHARTS_USE_NAMESPACE

#define MAX_X   120
#define MAX_Y   1000

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class Worker;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    //退出
    void on_actionExit_triggered();

    //打开串口
    void on_actionConnect_triggered();

    //关闭串口
    void on_actionClose_triggered();

    //刷新串口
    void on_actionRefresh_triggered();

    //保存数据
    void on_actionsave_triggered();

    //读取数据
    void on_actionread_triggered();

    //从串口接收数据
    void ReadSerialData();

    //打印按钮
    void on_actionprint_triggered();

    //chart
    void slotTimeOut();

    //结果
    void handleResults(const QString &s,double value);
private:
    //实现软件参变量的初始化设定
    void InitialSetting();

    //搜索可用的串口，并添加到串口组合框
    void SearchSerialPorts();

    //初始化 chart
    void InitChart();

    //保存Chart为图片
    void SaveChart2Image();
private:
    Ui::MainWindow *ui;
    QSerialPort *serialPort;
    QChart* m_pChart;
    QTimer* m_ptimer;
    QSplineSeries* m_pSer0;			//曲线
    QSplineSeries* m_pSer1;			//曲线
    QSplineSeries* m_pSer2;			//曲线
    int receivedBytes;
    int transmitBytes;
    uint8_t snIndex;
    ///
    double ZXtemp;
    double BMtemp;
    double LNtemp;

    int num = 0;
    int count = 0;
     Worker *workerThread;
};
#endif // MAINWINDOW_H
